

package trim.gui.testing.models;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import trim.common.inputdata.FormatOrder;
import trim.common.result.TrimmedFormatOrder;

/**
 * Модель для отображения ВТ который будет нарезан по конкретному решению
 *
 * Created 21.12.2008 20:23:57
 * @author Саковнич Дмитрий
 */
public class ProductionTableModel extends AbstractTableModel implements IRowManipulationTableModel
{
  private FormatOrder[] input;
  private TrimmedFormatOrder[] out;

  public ProductionTableModel(List<FormatOrder> input,List<TrimmedFormatOrder> out)
  {
    this.input=input.toArray(new FormatOrder[0]);

    this.out=new TrimmedFormatOrder[this.input.length];
    for(int i=0;i<this.input.length;i++)
    {
      this.out[i]=new TrimmedFormatOrder(this.input[i].getFormat(),0);
      for(TrimmedFormatOrder fc:out)
      {
        if(fc.getFormat().equals(this.out[i].getFormat()))
        {
          this.out[i]=fc;
          break;
        }
      }
    }
    
  }


  public int getRowCount()
  {
    return input.length;
  }

  public int getColumnCount()
  {
    return 4;
  }

  public Object getValueAt(int rowIndex,int columnIndex)
  {
    FormatOrder in=input[rowIndex];
    switch(columnIndex)
    {
      case 0:return in.getFormat().getLength();
      case 1:return in.getCount()-in.getDeltaM();
      case 2:return input.length!=out.length?0:out[rowIndex].getCount();
      case 3:return in.getCount()+in.getDeltaP();
    }
    return 0;
  }

  @Override
  public Class<?> getColumnClass(int columnIndex)
  {
    return Integer.class;
  }

  @Override
  public String getColumnName(int column)
  {
    switch(column)
    {
      case 0:return "Format";
      case 1:return "Low";
      case 2:return "Res";
      case 3:return "High";
    }
    return super.getColumnName(column);
  }

  public void addRow()
  {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public void insertRow(int r)
  {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public void removeRow(int r)
  {
    throw new UnsupportedOperationException("Not supported yet.");
  }

  public Object getObject(int r)
  {
    return input[r].getFormat();
  }

}
